// MessageClassDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MessageClassDlg.h"
#include "globals.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMessageClassDlg dialog


CMessageClassDlg::CMessageClassDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CMessageClassDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMessageClassDlg)
	m_DoNotShow = FALSE;
	m_Text = _T("");
	//}}AFX_DATA_INIT
	bDoNotShow = TRUE;
	cYesText = "Yes";
	cNoText = "No";
	cOKText = "OK";
}


void CMessageClassDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMessageClassDlg)
	DDX_Control(pDX, IDC_MCICON, m_mcicon);
	DDX_Check(pDX, IDC_DONOTSHOW, m_DoNotShow);
	DDX_Text(pDX, IDC_TEXT, m_Text);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMessageClassDlg, CDialogEx)
	//{{AFX_MSG_MAP(CMessageClassDlg)
	ON_BN_CLICKED(IDC_NOBUTTON, OnNobutton)
	ON_BN_CLICKED(IDC_YES, OnYes)
	ON_BN_KILLFOCUS(IDC_DONOTSHOW, OnBnKillfocusDonotshow)
	ON_BN_CLICKED(IDC_DONOTSHOW, OnBnClickedDonotshow)//}}AFX_MSG_MAP
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDOK, &CMessageClassDlg::OnBnClickedOk)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMessageClassDlg message handlers

void CMessageClassDlg::OnDonotshow() 
{
	UpdateData(TRUE);
}

void CMessageClassDlg::OnNo() 
{
	EndDialog(0);
}

BOOL CMessageClassDlg::GetShow()
{
	return m_DoNotShow;
}

void CMessageClassDlg::SetShow(BOOL donotshow)
{
	m_DoNotShow = donotshow;
}

void CMessageClassDlg::SetText(CString *str)
{
	m_Text = *str;
}

void CMessageClassDlg::SetText(char *str)
{
	strcpy_s(m_Text.GetBuffer(300), 300, str);
	m_Text.ReleaseBuffer();
}

void CMessageClassDlg::SetDoNotShow(BOOL show)
{
	if (show)
		bDoNotShow = TRUE;
	else
		bDoNotShow = FALSE;

}

BOOL CMessageClassDlg::OnInitDialog() 
{
	CDialogEx::OnInitDialog();
	CDialogEx::SetBackgroundColor(GetInt("BackgroundColor", RGB(255,255,255)), TRUE);
	// TODO: Add extra initialization here
	HICON		hIconIn;
	HINSTANCE	hInstResource;

	// Find correct resource handle
	hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(iIcon), RT_GROUP_ICON);

	// Set icon when the mouse is IN the button
	hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(iIcon), IMAGE_ICON, 0, 0, 0);
	
	m_mcicon.SetIcon(hIconIn);
	SetWindowText(cTitleStr);
	if (EnableOK)
	{
		GetDlgItem(IDOK)->ShowWindow(TRUE);
		//GetDlgItem(IDC_YES)->ShowWindow(FALSE);
		//GetDlgItem(IDC_NOBUTTON)->ShowWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDOK)->ShowWindow(FALSE);
		GetDlgItem(IDC_YES)->ShowWindow(TRUE);
		GetDlgItem(IDC_NOBUTTON)->ShowWindow(TRUE);
	}
	if (bDoNotShow)
		GetDlgItem(IDC_DONOTSHOW)->ShowWindow(SW_SHOW);
	else
		GetDlgItem(IDC_DONOTSHOW)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_NOBUTTON)->SetWindowText(cNoText);
	GetDlgItem(IDC_YES)->SetWindowText(cYesText);
	GetDlgItem(IDOK)->SetWindowText(cOKText);
	
	MessageBeep(-1);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}

void CMessageClassDlg::EnableOKButton(BOOL ok)
{
	if (ok)
		EnableOK = TRUE;
	else
		EnableOK = FALSE;
}

void CMessageClassDlg::SetIconQuestionMark()
{
	iIcon = IDI_QUESTIONMARK;
}

void CMessageClassDlg::SetIconStopSign()
{
	iIcon = IDI_STOPSIGN;

}

void CMessageClassDlg::SetIconExclamation()
{
	iIcon = IDI_EXCLAM;
}

void CMessageClassDlg::SetTitleText(CString *str)
{
	cTitleStr = *str;
}

void CMessageClassDlg::SetTitleText(char *str)
{
	strcpy_s(cTitleStr.GetBuffer(100), 100, str);
	cTitleStr.ReleaseBuffer();
}

void CMessageClassDlg::OnYes() 
{
	EndDialog(1);  //Left Button
}

void CMessageClassDlg::OnNobutton() 
{
	EndDialog(2);	//Right button
}

void CMessageClassDlg::OnBnClickedOk()
{
	EndDialog(0);  //Middle button
	//CDialog::OnOK();
}

void CMessageClassDlg::OnBnKillfocusDonotshow()
{
	UpdateData(TRUE);
}

void CMessageClassDlg::OnBnClickedDonotshow()
{
	UpdateData(TRUE);
}

void CMessageClassDlg::SetLeftText(char *str) 
{
	cYesText = str;
}

void CMessageClassDlg::SetRightText(char *str)
{
	cNoText = str;	
}

void CMessageClassDlg::SetLeftText(CString *str) 
{
	GetDlgItem(IDC_YES)->SetWindowText(*str);
}

void CMessageClassDlg::SetRightText(CString *str)
{
	GetDlgItem(IDC_NOBUTTON)->SetWindowText(*str);
}

void CMessageClassDlg::SetMiddleText(char *str) 
{
	cOKText = str;
}

void CMessageClassDlg::SetMiddleText(CString *str) 
{
	GetDlgItem(IDOK)->SetWindowText(*str);
}
